package net.edisoft.controller;

import java.util.List;

import net.edisoft.model.Detail;
import net.edisoft.model.Header;
import net.edisoft.util.HibernateUtil;

import org.hibernate.HibernateException;
import org.hibernate.classic.Session;

public class InvoiceController extends HibernateUtil {

	
	public List<Header> list() {
		
		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();
		List<Header> invoice = null;
		try {
			
			invoice = (List<Header>)session.createQuery("from Header").list();
			
		} catch (HibernateException e) {
			e.printStackTrace();
			session.getTransaction().rollback();
		}
		session.getTransaction().commit();
		return invoice;
	}

	public List<Detail> listDetail() {
		
		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();
		List<Detail> details = null;
		try {
			
			details = (List<Detail>)session.createQuery("from Detail").list();
			
		} catch (HibernateException e) {
			e.printStackTrace();
			session.getTransaction().rollback();
		}
		session.getTransaction().commit();
		return details;
	}

}
